const path = require('path')
const { override, fixBabelImports, addWebpackAlias, addLessLoader, adjustStyleLoaders } = require('customize-cra');

module.exports = function override(config, env) {
    // do stuff with the webpack config...
    return config;
};
module.exports = override(
    fixBabelImports('import', {
        libraryName: 'antd-mobile',
        style: 'css',
    }),
    // 配置路径
    addWebpackAlias({
        assets: path.resolve(__dirname, './src/assets'),
        "@": path.resolve(__dirname, "./src"),
    }),
    // 配置less 
    addLessLoader({
        lessOptions: {
            javascriptEnabled: true,
            modifyVars: { '@primary-color': '#1DA57A' },
        },
        sourceMap: true,
    }),
    adjustStyleLoaders(({ use: [, css] }) => {
        css.options.sourceMap = true;
        css.options.modules = {
            // 配置默认的样式名称规则
            localIdentName: '[name]__[local]--[hash:base64:5]',
            getLocalIdent: (loaderContext, localIdentName, localName, options) => {
                // 处理antd 的样式
                if (loaderContext.resourcePath.includes('node_modules')) {
                    return localName;
                }       
            }
        }
    })
);
